<?php
$blogEntries = array();

$query = "SELECT id, created, title, alias, introduction, createdBy ".
		 "FROM blogEntries ".
		 "WHERE visible = 1 ".
		 "ORDER BY created DESC";

if ($res1 = $db->runQuery($query)) {
	while ($row1 = $db->getRow($res1)) {
		list($date, $time) = explode(" ", $row1["created"]);
		list($year, $month, $day) = explode("-", $date);
		list($hour, $minute, $second) = explode(":", $time);
		//$month = strtoupper(substr($content->langmsg[(int)$month], 0, 3));
		// Consultamos el número de comentarios de la entrada
		$query = "SELECT count(*) AS total FROM blogComments WHERE entryId = '".$row1["id"]."' AND status = 1";
		if (!$res2 = $db->runQuery($query)) {
			$comments = 0;
		} else {
			$row2 = $db->getRow($res2);
			$comments = $row2["total"];
		}
		// Añadimos los datos al array de entradas
		$url = BASE_URL.$lang."/blog/".$row1["alias"]."/";
		$blogEntries[] = array(
			"url" => $url,
			"title" => utf8_encode($row1["title"]),
			"introduction" => utf8_encode($row1["introduction"]),
			"comments" => $comments,
			"date" => $day." de ".strtolower($content->langmsg[(int)$month])." de ".$year,
			"time" => $hour.":".$minute,
			"author" => utf8_encode($row1["createdBy"]),
			"sharelinks" => $content->generateShareLinks($url)
		);
	}
}
$content->assign("blogEntries", $blogEntries);
?>
